if exists (select 1
            from  sysobjects
           where  id = object_id('bd_view_leave_detail')
            and   type = 'V')
   drop view bd_view_leave_detail
go

/*==============================================================*/
/* View: bd_view_leave_detail                                   */
/*==============================================================*/
create view bd_view_leave_detail as
SELECT detail.id, detail.user_serial, u.user_no, u.user_lname user_name, u.user_dep dep_id, u.dep_name,
 detail.bh leave_type_id, jl.mc leave_type_name, detail.kssj, detail.jssj, detail.jsjg, detail.bz, detail.gly_no,
 detail.shenhe, detail.lx, detail.czrq, detail.leave_length, detail.Business_purposes, detail.in_Place, detail.accommodation,
 detail.ACCOMMODATION_DAYS, detail.schedule, detail.img_path, detail.order_id, lv.order_no, detail.whether_validity, detail.is_deduct,
 detail.remove_user remove_user_id, rv.user_no remove_user_no, rv.user_lname remove_user_name,
 detail.remove_time, detail.return_remark, detail.settle_year, detail.settle_month
FROM lr_kqingj detail
INNER JOIN bd_leave_order lv ON lv.order_id = detail.order_id
INNER JOIN kt_qingj jl ON jl.bh = detail.bh
INNER JOIN (
    SELECT
      user_serial, user_no, user_lname, user_dep, dep_name
    FROM bd_view_user_all
  ) u ON u.user_serial = detail.user_serial
LEFT JOIN (
    SELECT
      user_serial, user_no, user_lname
    FROM bd_view_user_all
  ) rv ON rv.user_serial = detail.remove_user
go
